/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.tutorial.sql;

import com.wisnu.tutorial.configuration.ServerConfiguration;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Wisnu Wardoyo
 */
public class Connection {

    private java.sql.Connection con;
    private ServerConfiguration serverConfiguration = new ServerConfiguration();
    private final List<String> config = serverConfiguration.getServerConfiguration("src/com/wisnu/tutorial/configuration/serverConfiguration.xml");

    public boolean check() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://" + config.get(0) + "/"
                    + config.get(1) + "", "" + config.get(2) + "", "" + config.get(3) + "");
            System.out.println("Connection Estabilised");
            return true;
        } catch (ClassNotFoundException | SQLException ex) {
            System.err.println("Connection Error \n" + ex);
            return false;
        }
    }

    public java.sql.Connection getCon() {
        return con;
    }

    public void setCon(java.sql.Connection con) {
        this.con = con;
    }

}
